package com.shujia.tf

import org.apache.flink.api.common.functions.MapFunction
import org.apache.flink.streaming.api.scala._

object Demo1Map {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    val listDS: DataStream[Int] = env.fromCollection(List(1, 2, 3, 4, 5, 6, 7, 8, 9))

    //scala api
    val scalaApiDS: DataStream[Int] = listDS.map(i => i * 2)
    //scalaApiDS.print()


    //java api
    val javaApiDS: DataStream[Int] = listDS.map(new MapFunction[Int, Int] {
      /**
        * 数据一条一条传递给map方法
        *
        * @param value ： 一行数据
        * @return ： 返回处理之后的数据
        */
      override def map(value: Int): Int = {
        value * 2
      }
    })

    javaApiDS.print()


    env.execute()
  }

}
